package com.didibigdata.servlets;

import com.didibigdata.Repositories.WorkTimeRepository;
import com.didibigdata.entities.Work;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/WorkTimeServlet")
public class WorkTimeServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        WorkTimeRepository workTimeRepository = new WorkTimeRepository();
        List<Work> workList = workTimeRepository.getWorkList();
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(workList);
        resp.setContentType("text/html; charset=utf-8");
        resp.getWriter().write(json);
    }
}
